package com.zengguang.testkaoshi.controller;

import com.zengguang.testkaoshi.pojo.Loginlog;
import com.zengguang.testkaoshi.services.impl.LoginLogService;
import com.zengguang.testkaoshi.tool.ResponseMessage;
import com.zengguang.testkaoshi.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *对外提供数据服务接口
 */
@Api(tags = "loginlog")
@RestController
@CrossOrigin
public class LoginlogAction {
    @Autowired
    private LoginLogService service;

    @ApiOperation(value = "班级添加方法")
    @RequestMapping(value = "/addLoginlog",method = RequestMethod.GET)
    public ResponseMessage add(Loginlog loginlog){
        int isAdd=0;
        //传入数据的判断
        //(1)实体对象不能为空
        if (loginlog!=null) {
                //添加角色数据
                isAdd = service.insertLoginlog(loginlog);
                if (isAdd==1){
                    return Result.success("保存成功");
                }else {
                    return Result.error("保存失败");
                }
        }
        return Result.error("保存失败");
    }

    @ApiOperation(value = "查询全部")
    @RequestMapping(value = "/getAllLoginlog",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public ResponseMessage getAll(Loginlog loginlog){
        Map<String, List> map=new HashMap<>();
        List<Loginlog> list=service.getWhereAll(loginlog);
        map.put("list",list);
        return Result.success("200",map);
    }
}
